#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=5e5+5;
int n,k;
int a[Maxn];
int pre[Maxn],nxt[Maxn];

struct node{
	int id,val;
	inline bool operator<(const node&a)const{return a.val>val;}
};
priority_queue<node>heap;
int vis[Maxn];
inline void ins(int i){
	int tp;
	if(a[i]==a[nxt[i]]){
		if(i>nxt[i])tp=i;
		else tp=nxt[i];
	}else{
		if(a[i]<a[nxt[i]])tp=nxt[i];
		else tp=i;
	}
	heap.push({tp,a[i]+a[nxt[i]]});
}
inline void del(int id){
	vis[id]=1;
	nxt[pre[id]]=nxt[id];
	pre[nxt[id]]=pre[id];
	ins(pre[id]);
}
int main(){
	freopen("sub.in","r",stdin);
	freopen("sub.out","w",stdout);
	n=read();k=read();
	for(int i=1;i<=n;i++)a[i]=read();
	
	pre[1]=n;nxt[1]=2;
	pre[n]=n-1;nxt[n]=1;
	for(int i=2;i<n;i++){
		pre[i]=i-1;nxt[i]=i+1;
	}
	for(int i=1;i<=n;i++)ins(i);
	int tot=n-k;
	while(tot--){
		while(vis[heap.top().id])heap.pop();
		del(heap.top().id);heap.pop();
	}
	while(vis[heap.top().id])heap.pop();
	
//	for(int i=1;i<=n;i++)printf("fewfw %d %d\n",i,vis[i]);
	
	printf("%d\n",heap.top().val);
	return 0;
}

